﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.ComponentModel;
using System.Windows;
using System.Xml.Serialization;

namespace AssignmentsManage.DataClasses
{
    [XmlRootAttribute(ElementName = "Course", IsNullable = false)]
    public class Course : INotifyPropertyChanged
    {
        #region Constructors
        
        public Course()
        { 
            //ActivityTypeWorths = new List<ActivityTypeWorth>();
            //for (int i = 0; i < Enum.GetValues(typeof(EnumInfo.ActivityType)).Length; i++)
            //{
            //    ActivityTypeWorths.Add(new ActivityTypeWorth((EnumInfo.ActivityType)i));
            //}
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="courseCode">Unique ID of the course</param>
        /// <param name="title">Full title of the course</param>
        public Course(string courseCode, string title)
            : this()
        {
            CourseCode = courseCode;
            Title = title;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="courseCode">Unique ID of the course</param>
        /// <param name="title">Full title of the course</param>
        /// <param name="idColour">Colour used to identify the course</param>
        public Course(string courseCode, string title, Color idColour)
            : this(courseCode, title)
        {
            IDColour = idColour;
        }

        #endregion

        #region Properties

        private string _CourseCode;
        /// <summary>
        /// Unique code of the course
        /// </summary>
        [XmlElementAttribute("CourseCode")]
        public string CourseCode
        {
            get
            {
                return _CourseCode;
            }
            set
            {
                _CourseCode = value;
                OnPropertyChanged("CourseCode");
            }
        }

        private string _Title;
        /// <summary>
        /// Title or full name of the course
        /// </summary>
        [XmlElementAttribute("Title")]
        public string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                _Title = value;
                OnPropertyChanged("Title");
            }
        }

        private Color _IDColour;
        /// <summary>
        /// Unique colour used to identify the course
        /// </summary>
        [XmlElementAttribute("IDColour")]
        public Color IDColour
        {
            get
            {
                return _IDColour;
            }
            set
            {
                _IDColour = value;
                OnPropertyChanged("IDColour");
            }
        }

        private List<ActivityTypeWorth> _ActivityTypeWorths;
        [XmlArray("ActivityTypeWorths"), XmlArrayItem("ActivityTypeWorthItem", typeof(ActivityTypeWorth))]
        public List<ActivityTypeWorth> ActivityTypeWorths
        {
            get
            {
                return _ActivityTypeWorths;
            }
            set
            {
                _ActivityTypeWorths = value;
                OnPropertyChanged("ActivityTypeWorths");
            }
        }

        private List<SetCLib.TitleValueXML> _CustomProperties;
        [XmlArray("CustomProperties"), XmlArrayItem("PropertyItem", typeof(SetCLib.TitleValueXML))]
        public List<SetCLib.TitleValueXML> CustomProperties
        {
            get
            {
                return _CustomProperties;
            }
            set
            {
                _CustomProperties = value;
                OnPropertyChanged("CustomProperties");
            }
        }

        private double _TotalGrade;
        [XmlIgnore()]
        public double TotalGrade
        {
            get
            {
                return _TotalGrade;
            }
            set
            {
                _TotalGrade = value;
                OnPropertyChanged("TotalGrade");
            }
        }

        #endregion

        #region Methods


        #endregion

        #region NotifyChanges

        // Create the OnPropertyChanged method to raise the event
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
